﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;

namespace FighttheLandOwner.GameCore
{
    class Card
    {
        public CardColor Color
        {
            get
            {
                if (Type == CardType.Heart || Type == CardType.Diamond)
                    return CardColor.Red;
                return CardColor.Black;
            }
        }
        public CardType Type { get; set; }
        public CardValue Value { get; set; }

        /// <summary>
        /// 将扑克牌的数值转化为数值
        /// </summary>
        /// <returns></returns>
        public int ToInt()
        {
            int result;
            switch (Value)
            {
                case CardValue.A:
                    result = 14;
                    break;
                case CardValue.Eight:
                    result = 8;
                    break;
                case CardValue.Five:
                    result = 5;
                    break;
                case CardValue.Four:
                    result = 4;
                    break;
                case CardValue.J:
                    result = 11;
                    break;
                case CardValue.Joker:
                    result = 100;
                    break;
                case CardValue.K:
                    result = 13;
                    break;
                case CardValue.Nine:
                    result = 9;
                    break;
                case CardValue.Q:
                    result = 12;
                    break;
                case CardValue.Seven:
                    result = 7;
                    break;
                case CardValue.Six:
                    result = 6;
                    break;
                case CardValue.Ten:
                    result = 10;
                    break;
                case CardValue.Three:
                    result = 3;
                    break;
                case CardValue.Two:
                    result = 20;
                    break;
                default:
                    result = 0;
                    break;
            }
            return result;
        }

        /// <summary>
        /// 获取对应牌的值
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string GetAttributeValue(CardValue value)
        {
            string result;
            switch(value)
            {
                case CardValue.A:
                    result = "A";
                    break;
                case CardValue.Eight:
                    result = "8";
                    break;
                case CardValue.Five:
                    result = "5";
                    break;
                case CardValue.Four:
                    result = "4";
                    break;
                case CardValue.J:
                    result = "J";
                    break;
                case CardValue.Joker:
                    result = "Joker";
                    break;
                case CardValue.K:
                    result = "K";
                    break;
                case CardValue.Nine:
                    result = "9";
                    break;
                case CardValue.Q:
                    result = "Q";
                    break;
                case CardValue.Seven:
                    result = "7";
                    break;
                case CardValue.Six:
                    result = "6";
                    break;
                case CardValue.Ten:
                    result = "10";
                    break;
                case CardValue.Three:
                    result = "3";
                    break;
                case CardValue.Two:
                    result = "2";
                    break;
                default:
                    result = null;
                    break;
            }
            return result;
        }

        /// <summary>
        /// 获取对应牌的颜色
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        public static string GetAttributeValue(CardColor color)
        {
            switch(color)
            {
                case CardColor.Black:
                    return "Black";
                case CardColor.Red:
                    return "Red";
                default:
                    return null;
            }
        }

        /// <summary>
        /// 获取对应牌的类型
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string GetAttributeValue(CardType type)
        {
            switch(type)
            {
                case CardType.Clubs:
                    return "Clubs";
                case CardType.Diamond:
                    return "Diamond";
                case CardType.Heart:
                    return "Heart";
                case CardType.Spade:
                    return "Spade";
                default:
                    return null;
            }
        }

        /// <summary>
        /// 获取字符串牌对应的牌的牌值
        /// </summary>
        /// <param name="cardvalue"></param>
        /// <returns></returns>
        public static CardValue GetCardValue(string value)
        {
            CardValue result;
            switch (value)
            {
                case "A":
                    result = CardValue.A;
                    break;
                case "8" :
                    result = CardValue.Eight;
                    break;
                case "5":
                    result =CardValue.Five;
                    break;
                case "4":
                    result = CardValue.Four;
                    break;
                case  "J":
                    result =CardValue.J;
                    break;
                case "Joker":
                    result = CardValue.Joker;
                    break;
                case "K":
                    result = CardValue.K;
                    break;
                case "9":
                    result = CardValue.Nine;
                    break;
                case "Q":
                    result = CardValue.Q;
                    break;
                case "7":
                    result = CardValue.Seven;
                    break;
                case "6":
                    result = CardValue.Six;
                    break;
                case "10":
                    result = CardValue.Ten;
                    break;
                case "3":
                    result = CardValue.Three;
                    break;
                case "2":
                    result = CardValue.Two;
                    break;
                default:
                    result = CardValue.A;
                    break;
            }
            return result;
        }

        /// <summary>
        /// 获取字符串牌对应的牌的类型
        /// </summary>
        /// <param name="cardtype"></param>
        /// <returns></returns>
        public static CardType GetCardType(string type)
        {
            switch (type)
            {
                case "Clubs":
                    return CardType.Clubs;
                case "Diamond":
                    return CardType.Diamond;
                case "Heart":
                    return CardType.Heart;
                case "Spade":
                    return CardType.Spade;
                default:
                    return CardType.Clubs;
            }
        }

        /// <summary>
        /// 获取字符串牌对应的牌的颜色
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        public static CardColor GetCardColor(string color)
        {
            switch (color)
            {
                case "Black":
                    return CardColor.Black;
                case "Red":
                    return CardColor.Red;
                default:
                    return CardColor.Black ;
            }
        }

        public Card(CardType type, CardValue value)
        {
            Type = type;
            Value = value;
        }
    }

    enum CardValue
    {
        A,
        Two,
        Three,
        Four,
        Five,
        Six,
        Seven,
        Eight,
        Nine,
        Ten,
        J,
        Q,
        K,
        Joker
    }

    enum CardColor
    {
        Red,
        Black
    }

    enum CardType
    {
        /// <summary>
        /// 红桃
        /// </summary>
        Heart,
        /// <summary>
        /// 方片
        /// </summary>
        Diamond,
        /// <summary>
        /// 黑桃
        /// </summary>
        Spade,
        /// <summary>
        /// 梅花
        /// </summary>
        Clubs
    }
}
